package com.zf.bm.common.core.sys.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.zf.bm.common.core.sys.entity.User;
import com.zf.bm.common.core.sys.service.ISignInterface;
import com.zf.bm.common.core.sys.service.UserService;
import com.zf.bm.common.utils.JsonUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;

/**
 * <p>
 * 用户签名实现类
 * </p>
 *
 * @author guojing
 * @since 2023-07-06
 */
@Component("user")
public class UserSignServiceImpl implements ISignInterface {
    @Resource
    private UserService userService;

    @Override
    public ImmutablePair<String, String> getSignData(Integer id) {
        User user = userService.getById(id);
        if (ObjectUtils.isEmpty(user)) {
            return null;
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("email", user.getEmail());
        jsonObject.put("loginIp", user.getLoginIp());
        jsonObject.put("phone", user.getPhone());
        return ImmutablePair.of(JsonUtils.objectToString(jsonObject), user.getSm3());
    }
}
